home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Text / WASTE / WASTE 1.1.2 Distribution / Demo Source / WEDemoInit.p < prev    next >
Encoding:
Text File  |  1995-10-12  |  4.0 KB  |  152 lines  |  [TEXT/CWIE]

  1. unit WEDemoInit;
  2.  
  3. { WASTE DEMO PROJECT: }
  4. { Initialization & Finalization Routines }
  5.  
  6. { Copyright © 1993-1995 Marco Piovanelli }
  7. { All Rights Reserved }
  8.  
  9. interface
  10.     uses
  11.         WEDemoIntf;
  12.  
  13.     function Initialize: OSErr;
  14.     procedure Finalize;
  15.  
  16. implementation
  17.     uses
  18.         Dialogs, Fonts, GestaltEqu, Scrap, TextServices, WEDemoEvents, WEDemoMenus, WEDemoWindows, WEDemoDrags, WEDemoPictures, WEDemoSounds;
  19.  
  20.     var
  21.  
  22. { static variables }
  23.  
  24.         sMyTrackingHandler: DragTrackingHandlerUPP;
  25.         sMyReceiveHandler: DragReceiveHandlerUPP;
  26.  
  27.     function Initialize: OSErr;
  28.  
  29.         const
  30.             kMinSystemVersion = $700;
  31.             kScrapThreshold = 4 * 1024;
  32.  
  33.         var
  34.             response: LongInt;
  35.             scrapResult: LongInt;
  36.  
  37.         procedure CheckErr (err: OSErr);
  38.         begin
  39.             if (err <> noErr) then
  40.                 begin
  41.                     Initialize := err;
  42.                     ErrorAlert(err);
  43.                     Exit(Initialize);
  44.                 end;
  45.         end;  { CheckErr }
  46.  
  47.     begin
  48.         Initialize := noErr;
  49.  
  50. { expand the zone to its maximum size }
  51.         MaxApplZone;
  52.  
  53. { allocate some extra master pointer blocks }
  54.         MoreMasters;
  55.         MoreMasters;
  56.         MoreMasters;
  57.         MoreMasters;
  58.         MoreMasters;
  59.         MoreMasters;
  60.  
  61. { initialize the Toolbox }
  62. {$IFC NOT UNDEFINED THINK_PASCAL}
  63.         InitGraf(@thePort);
  64. {$ELSEC}
  65.         InitGraf(@qd.thePort);
  66. {$ENDC}
  67.         InitFonts;
  68.         InitWindows;
  69.         InitMenus;
  70.         TEInit;
  71.         InitDialogs(nil);
  72.         InitCursor;
  73.         FlushEvents(everyEvent, 0);
  74.  
  75. { if desk scrap is too large, unload it }
  76.         if (InfoScrap^.scrapSize > kScrapThreshold) then
  77.             scrapResult := UnloadScrap;
  78.  
  79. { make sure system software version is 7.0 or newer }
  80.         if (Gestalt(gestaltSystemVersion, response) <> noErr) | (response < kMinSystemVersion) then
  81.             begin
  82. {$IFC NOT UNDEFINED THINK_PASCAL}
  83.                 SetCursor(arrow);
  84. {$ELSEC}
  85.                 SetCursor(qd.arrow);
  86. {$ENDC}
  87.                 response := Alert(kAlertNeedSys7, nil);
  88.                 Initialize := -1;
  89.                 Exit(Initialize);
  90.             end;
  91.  
  92. { determine whether Color QuickDraw is available }
  93.         gHasColorQD := (Gestalt(gestaltQuickDrawVersion, response) = noErr) & (response >= gestalt8BitQD);
  94.  
  95. { determine whether the Drag Manager is available }
  96.         gHasDragAndDrop := (Gestalt(gestaltDragMgrAttr, response) = noErr) & BTST(response, gestaltDragMgrPresent);
  97.  
  98. {$IFC GENERATINGCFM}
  99.         gHasDragAndDrop := gHasDragAndDrop & (@NewDrag <> nil);
  100. {$ENDC}
  101.  
  102. { determine whether the Text Services Manager is available }
  103.         gHasTextServices := (Gestalt(gestaltTSMgrVersion, response) = noErr);
  104.  
  105. { register this application with the TSM }
  106.         if (gHasTextServices) then
  107.             CheckErr(InitTSMAwareApplication);
  108.  
  109. { install default drag handlers }
  110.         if (gHasDragAndDrop) then
  111.             begin
  112.                 sMyTrackingHandler := NewDragTrackingHandlerProc(@MyTrackingHandler);
  113.                 sMyReceiveHandler := NewDragReceiveHandlerProc(@MyReceiveHandler);
  114.                 CheckErr(InstallTrackingHandler(sMyTrackingHandler, nil, nil));
  115.                 CheckErr(InstallReceiveHandler(sMyReceiveHandler, nil, nil));
  116.             end;
  117.  
  118. { install WASTE handlers for PICT objects }
  119.         CheckErr(WEInstallObjectHandler(kTypePicture, weNewHandler, NewWENewObjectProc(@HandleNewPicture), nil));
  120.         CheckErr(WEInstallObjectHandler(kTypePicture, weDisposeHandler, NewWEDisposeObjectProc(@HandleDisposePicture), nil));
  121.         CheckErr(WEInstallObjectHandler(kTypePicture, weDrawHandler, NewWEDrawObjectProc(@HandleDrawPicture), nil));
  122.  
  123. { install WASTE handlers for snd objects }
  124.         CheckErr(WEInstallObjectHandler(kTypeSound, weNewHandler, NewWENewObjectProc(@HandleNewSound), nil));
  125.         CheckErr(WEInstallObjectHandler(kTypeSound, weDrawHandler, NewWEDrawObjectProc(@HandleDrawSound), nil));
  126.         CheckErr(WEInstallObjectHandler(kTypeSound, weClickHandler, NewWEClickObjectProc(@HandleClickSound), nil));
  127.  
  128. { perform other initialization chores }
  129.         CheckErr(InitializeEvents);
  130.         CheckErr(InitializeMenus);
  131.  
  132.     end;  { Initialize }
  133.  
  134.     procedure Finalize;
  135.     begin
  136.  
  137. { remove drag handlers }
  138.         if (gHasDragAndDrop) then
  139.             begin
  140.                 if (RemoveTrackingHandler(sMyTrackingHandler, nil) <> noErr) then
  141.                     ;
  142.                 if (RemoveReceiveHandler(sMyReceiveHandler, nil) <> noErr) then
  143.                     ;
  144.             end;
  145.  
  146. { notify text services that we're closing down }
  147.         if (gHasTextServices) then
  148.             if (CloseTSMAwareApplication <> noErr) then
  149.                 ;
  150.     end;  { Finalize }
  151.  
  152. end.